<?php
/**
 * MODEL CREATOR 2012
 * @package ModelCreator
 * @subpackage Language  
 * @copyright 2012/11/10 - MODEL CREATOR
 * @version 1.0  
 * @since File since version 1.0  
 */

/**
 * Class that indentify and set application language
 * @package ModelCreator
 * @subpackage Language  
 * @author Renato Laranjo <renatolaranjo@gmail.com> 
 * @release: $package_version$
 * @since classe dal 2012   
 */

class ModelCreator_Language_Selector {
    /**
     * Constant that contains name of language file
     * @var string 
     */
    public $filename = 'Languages.ini';

    /**
     * Function used to detect browser language and parse with ini file
     * @return array
     */
    public function detect() {
        $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        $arrIni = parse_ini_file($this->filename, true);
        if(key_exists($lang, $arrIni)){ 
            return $arrIni[$lang];
        }else{
            return $arrIni['en'];
        }
        
    }

}
